//
//  HelpBargainCollectionHeaderView.swift
//  TestDemo
//
//  Created by ayin on 2019/3/19.
//  Copyright © 2019 aYin. All rights reserved.
//

import UIKit
//MARK: - HelpBargainCollectionHeaderView--------------------------
class HelpBargainCollectionHeaderView: UICollectionReusableView {
    //MARK: - 声明属性
    lazy var contentView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.white
        return view
    }()
    
    //店铺信息view
    lazy var topShopInfoView: HelpBargainTopShopInfoView = {
        let view = HelpBargainTopShopInfoView()
        return view
    }()
    
    //商品信息view
    lazy var goodsInfoView: HelpBargainGoodsInfoView = {
        let view = HelpBargainGoodsInfoView()
        return view
    }()
    
    //活动结束时间view
    lazy var activityEndTimeView: HelpBargainActivityEndTimeView = {
        let view = HelpBargainActivityEndTimeView()
        return view
    }()
    
    //砍价进度view
    lazy var progressView: HelpBargainProgressView = {
        let view = HelpBargainProgressView()
        return view
    }()
    
    //砍价状态view
    lazy var statusView: HelpBargainStatusView = {
        let view = HelpBargainStatusView()
        view.isHidden = true
        return view
    }()
    
    //分享砍价按钮view
    lazy var sharBtnView: HelpBargainShareBtnView = {
        let view = HelpBargainShareBtnView()
        return view
    }()
    
    //好友助力view
    lazy var friendsView: HelpBargainFriendsView = {
        let view = HelpBargainFriendsView()
        return view
    }()
    
    lazy var bottomTitleLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 14.up), text: "———————— 更多砍价商品 ————————", textColor: UIColor.white, numberLine: 1, alignment: .center)
        return label
    }()
    
    var space: CGFloat = 12
    
    //MARK: - 初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    class func reuseId() -> String {
        return "HelpBargainCollectionHeaderView"
    }
    
    //MARK: - 搭建UI
    func setupUI() {
        self.backgroundColor = UIColor.blue
        self.addSubview(contentView)
        contentView.addSubview(topShopInfoView)
        contentView.addSubview(goodsInfoView)
        contentView.addSubview(activityEndTimeView)
        contentView.addSubview(progressView)
        contentView.addSubview(sharBtnView)
        contentView.addSubview(statusView)
        contentView.addSubview(friendsView)
        self.addSubview(bottomTitleLB)
        
        contentView.snp.makeConstraints { (make) in
            make.left.top.equalToSuperview().offset(space)
            make.right.equalToSuperview().offset(-space)
        }
        contentView.cornerRadius(10)
        
        topShopInfoView.snp.makeConstraints { (make) in
            make.left.top.right.equalToSuperview()
        }
        
        goodsInfoView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(space)
            make.right.equalToSuperview().offset(-space)
            make.top.equalTo(topShopInfoView.snp.bottom).offset(space)
        }
        
        activityEndTimeView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(goodsInfoView.snp.bottom)
        }
        
        progressView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(activityEndTimeView.snp.bottom)
        }
        
        statusView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(activityEndTimeView.snp.bottom)
        }
        
        sharBtnView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(progressView.snp.bottom).offset(20)
        }
        
        friendsView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(sharBtnView.snp.bottom).offset(20)
        }
        
        bottomTitleLB.snp.makeConstraints { (make) in
            make.top.equalTo(contentView.snp.bottom).offset(20)
            make.left.equalTo(space)
            make.right.equalTo(-space)
            make.bottom.equalToSuperview().offset(-20)
        }
    }
    
    //MARK: - 事件
    func refreshDatas(_ data: CutUserModel) {
        topShopInfoView.refreshDatas(data)
        goodsInfoView.refreshDatas(data)
        activityEndTimeView.refreshDatas(data)
        if data.status == .cutting {
            progressView.isHidden = false
            statusView.isHidden = true
            progressView.refreshDatas(data)
            
            sharBtnView.snp.remakeConstraints { (make) in
                make.left.right.equalToSuperview()
                make.top.equalTo(progressView.snp.bottom).offset(15)
            }
        }else {
            progressView.isHidden = true
            statusView.isHidden = false
            statusView.refreshDatas(data)
            
            sharBtnView.snp.remakeConstraints { (make) in
                make.left.right.equalToSuperview()
                make.top.equalTo(statusView.snp.bottom).offset(-10)
            }
        }
        sharBtnView.refreshDatas(data)
        friendsView.refreshDatas(data)
    }
    
    //MARK: - 代理
    
    //MARK: - 其他
}

//MARK: - HelpBargainTopShopInfoView--------------------------
class HelpBargainTopShopInfoView: UIView {
    //MARK: - 声明属性
    lazy var storesLogoLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 11.up), text: "专营店", textColor: UIColor.white, numberLine: 1, alignment: .center)
        label.backgroundColor = UIColor.red
        return label
    }()
    
    lazy var storesTitleLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 12.up), text: "NIKE官方专营店", textColor: UIColor.black, numberLine: 1, alignment: .left)
        return label
    }()
    
    lazy var intoShopBtn: UIButton = {
        let intoShopBtn = UIButton.makeButton(font: UIFont.systemFont(ofSize: 11.up), title: "进店", titleColor: UIColor.blue, image: nil, bgColor: UIColor.clear)
        intoShopBtn.addTarget(self, action: #selector(intoShopBtnAction(sender:)), for: .touchUpInside)
        return intoShopBtn
    }()
    
    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.lightGray
        return view
    }()
    
    var space: CGFloat = 12
    var intoShopBtnActionBlock:(() -> Void)?
    
    //MARK: - 初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    //MARK: - 搭建UI
    func setupUI() {
        addSubview(storesLogoLB)
        addSubview(storesTitleLB)
        addSubview(intoShopBtn)
        addSubview(lineView)
        
        storesLogoLB.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(space)
            make.height.equalTo(16.up)
            make.top.equalTo((40.up - 16.up)/2.0)
            make.width.equalTo(40.up)
        }
        storesLogoLB.cornerRadius(2)
        
        storesTitleLB.snp.makeConstraints { (make) in
            make.left.equalTo(storesLogoLB.snp.right).offset(space)
            make.top.equalToSuperview()
            make.height.equalTo(40.up)
            make.right.equalToSuperview().offset(-space-44.up)
        }
        
        intoShopBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-space)
            make.width.equalTo(44.up)
            make.height.equalTo(22.up)
            make.top.equalTo((40.up - 22.up)/2.0)
        }
        intoShopBtn.cornerRadius(11.up)
        intoShopBtn.border(UIColor.blue, width: 1)
        
        lineView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(space)
            make.right.equalToSuperview().offset(-space)
            make.top.equalTo(storesTitleLB.snp.bottom)
            make.height.equalTo(0.5)
            make.bottom.equalToSuperview()
        }
    }
    
    //MARK: - 事件
    func refreshDatas(_ data: CutUserModel) {
        storesLogoLB.text = "专营店"
        storesTitleLB.text = "NIKE官方专营店"
    }
    
    @objc func intoShopBtnAction(sender: UIButton) {
        if self.intoShopBtnActionBlock != nil {
            self.intoShopBtnActionBlock!()
        }
    }
}

//MARK: - HelpBargainGoodsInfoView--------------------------
class HelpBargainGoodsInfoView: UIView {
    //MARK: - 声明属性
    lazy var goodsImgView: UIImageView = {
        let imgView = UIImageView()
        imgView.backgroundColor = UIColor.colorWithHexString("D8D8D8")
        return imgView
    }()
    
    lazy var goodsTitleLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 13.up), text: "The Sun Chop 系列卫衣系列卫系列卫系卫衣哈利路亚哈哈", textColor: UIColor.black, numberLine: 0, alignment: .left)
        return label
    }()
    
    lazy var goodsPriceLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 30.up), text: "￥0.01 包邮", textColor: UIColor.orange, numberLine: 1, alignment: .left)
        return label
    }()
    
    lazy var goodsOriginalPriceLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 16.up), text: "￥499", textColor: UIColor.gray, numberLine: 1, alignment: .left)
        return label
    }()
    
    lazy var goodsReceiveLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 12.up), text: "1231人已领     剩余123件", textColor: UIColor.gray, numberLine: 1, alignment: .left)
        return label
    }()
    
    lazy var rulesBtn: UIButton = {
        let btn = UIButton.makeButton(font: UIFont.systemFont(ofSize: 8.up), title: "规则", titleColor: UIColor.gray, image: nil, bgColor: UIColor.colorWithHexString("E7E6E6"))
        return btn
    }()
    
    var space: CGFloat = 8
    
    //MARK: - 初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    //MARK: - 搭建UI
    func setupUI() {
        self.clipsToBounds = true
        self.backgroundColor = UIColor.colorWithHexString("F7F7F7")
        self.cornerRadius(4)
        addSubview(goodsImgView)
        addSubview(goodsTitleLB)
        addSubview(goodsPriceLB)
        addSubview(goodsOriginalPriceLB)
        addSubview(goodsReceiveLB)
        addSubview(rulesBtn)
        
        goodsImgView.snp.makeConstraints { (make) in
            make.left.top.equalTo(1)
            make.width.height.equalTo(120.up)
        }
        goodsImgView.cornerRadius(6)
        
        goodsTitleLB.snp.makeConstraints { (make) in
            make.left.equalTo(goodsImgView.snp.right).offset(space)
            make.right.equalToSuperview().offset(-space)
            make.top.equalToSuperview().offset(space)
            make.height.equalTo(36.up)
        }
        
        goodsPriceLB.snp.makeConstraints { (make) in
            make.left.equalTo(goodsTitleLB)
            make.top.equalTo(goodsTitleLB.snp.bottom).offset(13)
            make.height.equalTo(30.up)
        }
        
        goodsOriginalPriceLB.snp.makeConstraints { (make) in
            make.left.equalTo(goodsPriceLB.snp.right).offset(5)
            make.bottom.equalTo(goodsPriceLB)
            make.height.equalTo(20.up)
        }
        
        goodsReceiveLB.snp.makeConstraints { (make) in
            make.left.equalTo(goodsPriceLB)
            make.top.equalTo(goodsPriceLB.snp.bottom).offset(13)
            make.height.equalTo(17.up)
            make.right.bottom.equalToSuperview().offset(-space)
        }
        
        rulesBtn.snp.makeConstraints { (make) in
            make.bottom.right.equalToSuperview()
            make.width.equalTo(26.up)
            make.height.equalTo(15.up)
        }
        rulesBtn.cornerRadius(2)
    }
    
    //MARK: - 事件
    func refreshDatas(_ data: CutUserModel) {
        goodsPriceLB.text = "￥0.01 包邮"
        goodsPriceLB.attributedString("包邮", color: UIColor.orange, font: UIFont.systemFont(ofSize: 12.up))
        
//        goodsOriginalPriceLB.addDeleteLine(UIColor.colorWithHexString("979797"))
    }
}

//MARK: - HelpBargainActivityEndTimeView--------------------------
class HelpBargainActivityEndTimeView: UIView {
    //MARK: - 声明属性
    lazy var shengYuLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 13.up), text: "剩余", textColor: UIColor.black, numberLine: 1, alignment: .right)
        return label
    }()
    
    lazy var jieShuLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 13.up), text: "结束", textColor: UIColor.black, numberLine: 1, alignment: .left)
        return label
    }()
    
    var hoursLB: UILabel?
    var minutesLB: UILabel?
    var secondsLB: UILabel?
    var space: CGFloat = 12
    var timeLBWH: CGFloat = 24
    
    //MARK: - 初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    //MARK: - 搭建UI
    func setupUI() {
        self.addSubview(shengYuLB)
        self.addSubview(jieShuLB)
        
        let width: CGFloat = (screenWidth - 3*timeLBWH - 8*space)/2.0
        shengYuLB.snp.makeConstraints { (make) in
            make.left.equalTo(space)
            make.width.equalTo(width)
            make.height.equalTo(18.up)
            make.top.equalToSuperview().offset(25)
            make.bottom.equalToSuperview().offset(-25)
        }
        
        var left: CGFloat = width + space + space
        for i in 0 ..< 3 {
            let timeLB = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 14.up), text: "00", textColor: UIColor.white, numberLine: 1, alignment: .center)
            timeLB.backgroundColor = UIColor.black
            timeLB.cornerRadius(4)
            self.addSubview(timeLB)
            
            timeLB.snp.makeConstraints { (make) in
                make.left.equalTo(left)
                make.width.height.equalTo(timeLBWH)
                make.centerY.equalToSuperview()
            }
            
            if i != 2 {
                let pointLB = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 16.up), text: ":", textColor: UIColor.black, numberLine: 1, alignment: .center)
                self.addSubview(pointLB)
                pointLB.snp.makeConstraints { (make) in
                    make.left.equalTo(timeLB.snp.right)
                    make.width.equalTo(space)
                    make.height.equalTo(timeLBWH)
                    make.centerY.equalToSuperview()
                }
            }

            if i == 0 {
                self.hoursLB = timeLB
            }else if i == 1 {
                self.minutesLB = timeLB
            }else {
                self.secondsLB = timeLB
            }
            
            left = left + timeLBWH + space
        }
        
        jieShuLB.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-space)
            make.left.equalTo(left)
            make.centerY.equalToSuperview()
        }
    }
    
    //MARK: - 事件
    func refreshDatas(_ data: CutUserModel) {
        if self.hoursLB != nil {
            self.hoursLB!.text = "23"
        }
        
        if self.minutesLB != nil {
            self.minutesLB!.text = "22"
        }
        
        if self.secondsLB != nil {
            self.secondsLB!.text = "21"
        }
    }
}

//MARK: - HelpBargainProgressView--------------------------
class HelpBargainProgressView: UIView {
    //MARK: - 声明属性
    lazy var cutPriceLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 11.up), text: "已砍131.17元", textColor: UIColor.white, numberLine: 1, alignment: .center)
        label.backgroundColor = UIColor.colorWithHexString("FF6828")
        return label
    }()
    
    lazy var cutPriceBottomArrowImgView: UIImageView = {
        let arrowImgView = UIImageView()
        arrowImgView.backgroundColor = UIColor.red
        return arrowImgView
    }()
    
    lazy var progressView: UIProgressView = {
       let progressView = UIProgressView()
        progressView.progressTintColor = UIColor.colorWithHexString("707AFC")
        progressView.trackTintColor = UIColor.white
        return progressView
    }()
    
    lazy var salePriceLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 16.up), text: "¥ 499", textColor: UIColor.colorWithHexString("FF6828"), numberLine: 1, alignment: .center)
        return label
    }()
    
    lazy var minPriceLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 16.up), text: "¥ 0.01", textColor: UIColor.colorWithHexString("FF6828"), numberLine: 1, alignment: .center)
        return label
    }()
    
    var space: CGFloat = 25
    
    //MARK: - 初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    //MARK: - 搭建UI
    func setupUI() {
        self.addSubview(progressView)
        self.addSubview(cutPriceLB)
        self.addSubview(cutPriceBottomArrowImgView)
        self.addSubview(salePriceLB)
        self.addSubview(minPriceLB)
        
        progressView.snp.makeConstraints { (make) in
            make.width.equalTo(300.up)
            make.height.equalTo(12.up)
            make.center.equalToSuperview()
        }
        
        cutPriceBottomArrowImgView.snp.makeConstraints { (make) in
            make.width.height.equalTo(6.up)
            make.left.equalTo(progressView)
            make.bottom.equalTo(progressView.snp.top).offset(-6)
        }
        
        cutPriceLB.snp.makeConstraints { (make) in
            make.width.equalTo(84.up)
            make.height.equalTo(24.up)
            make.top.equalToSuperview()
            make.bottom.equalTo(cutPriceBottomArrowImgView.snp.top)
            make.right.equalTo(cutPriceBottomArrowImgView).offset(30)
        }
        
        salePriceLB.snp.makeConstraints { (make) in
            make.top.equalTo(progressView.snp.bottom)
            make.left.equalToSuperview().offset(space/2.0)
            make.height.equalTo(30.up)
            make.width.equalTo(50.up)
            make.bottom.equalToSuperview()
        }
        
        minPriceLB.snp.makeConstraints { (make) in
            make.top.equalTo(progressView.snp.bottom)
            make.right.equalToSuperview().offset(-space/2.0)
            make.height.equalTo(30.up)
            make.width.equalTo(50.up)
            make.bottom.equalToSuperview()
        }
    }
    
    //MARK: - 事件
    func refreshDatas(_ data: CutUserModel) {
        cutPriceLB.text = "已砍\(String(format:"%.2f",data.cutcountmoney))元"
        salePriceLB.text = "¥ \(data.salemoney)"
        minPriceLB.text = "¥ \(String(format:"%.2f",data.minprice))"
        
        let curProgress: Float = Float(data.cutcountmoney)/Float(data.salemoney)!
        progressView.progress = Float(curProgress)
        cutPriceBottomArrowImgView.snp.updateConstraints { (make) in
            make.left.equalTo(progressView).offset(300.up * CGFloat(curProgress))
        }
        
        var progressViewH: CGFloat = 12.up
        if data.ladderPricePrecent.count > 0 {
            progressViewH = 8.up
            progressView.border(UIColor.colorWithHexString("707AFC"), width: 0)
            progressView.trackTintColor = UIColor.colorWithHexString("E9E9E9")
            
            let nodeWH: CGFloat = 16.up
            var ladderArray: [Float] = data.ladderPricePrecent.components(separatedBy: ",").map { (str) -> Float in
                Float(str)!
            }
            ladderArray.insert(0, at: 0)
            ladderArray.append(1)
            for i in 0 ..< ladderArray.count {
                let progress = ladderArray[i]
                let price = Float(data.salemoney)! * progress
                
                let nodeImgView = UIImageView()
                nodeImgView.backgroundColor = UIColor.colorWithHexString("E9E9E9")
                if curProgress > progress {
                    nodeImgView.image = UIImage(named: "helpBargain_img_progress_node")
                }else {
                    nodeImgView.image = nil
                }
                self.addSubview(nodeImgView)
                
                var left: CGFloat = space
                if i != (ladderArray.count - 1) {
                    left = space + 300.up * CGFloat(progress)
                }else {
                    left = space + 300.up * CGFloat(progress) - nodeWH
                }
                nodeImgView.snp.makeConstraints { (make) in
                    make.left.equalTo(left)
                    make.width.height.equalTo(nodeWH)
                    make.centerY.equalToSuperview()
                }
                nodeImgView.cornerRadius(nodeWH/2.0)
                
                if i != 0 && i != (ladderArray.count - 1) {
                    let nodePriceLB = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 16.up), text: "¥ \(String(format:"%.2f",price))", textColor: UIColor.colorWithHexString("FF6828"), numberLine: 1, alignment: .center)
                    self.addSubview(nodePriceLB)
                    
                    nodePriceLB.snp.makeConstraints { (make) in
                        make.top.equalTo(progressView.snp.bottom)
                        make.bottom.equalToSuperview()
                        make.height.equalTo(30.up)
                        make.centerX.equalTo(nodeImgView)
                    }
                }
            }
        }else {
            progressViewH = 12.up
            progressView.border(UIColor.colorWithHexString("707AFC"), width: 1)
            progressView.trackTintColor = UIColor.white
        }
        
        progressView.snp.updateConstraints { (make) in
            make.height.equalTo(progressViewH)
        }
        progressView.cornerRadius(progressViewH/2.0)
        for imgView in progressView.subviews {
            if imgView is UIImageView {
                imgView.cornerRadius(progressViewH/2.0)
                imgView.clipsToBounds = true
            }
        }
    }
}

//MARK: - HelpBargainStatusView--------------------------
class HelpBargainStatusView: UIView {
    //MARK: - 声明属性
    lazy var bgImgView: UIImageView = {
        let bgImgView = UIImageView()
        bgImgView.image = UIImage(named: "helpBargain_img_grooming")
        return bgImgView
    }()
    
    lazy var statusLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 22.up), text: "已成功购买", textColor: UIColor.colorWithHexString("FF6828"), numberLine: 1, alignment: .center)
        label.backgroundColor = UIColor.clear
        return label
    }()
    
    var space: CGFloat = 33
    
    //MARK: - 初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    //MARK: - 搭建UI
    func setupUI() {
        self.addSubview(bgImgView)
        self.addSubview(statusLB)
        
        bgImgView.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.equalToSuperview().offset(space)
            make.right.equalToSuperview().offset(-space)
            make.height.equalTo(90.up)
        }
        
        statusLB.snp.makeConstraints { (make) in
            make.top.bottom.equalToSuperview()
            make.left.equalToSuperview().offset(space)
            make.right.equalToSuperview().offset(-space)
            make.height.equalTo(90.up)
        }
    }
    
    //MARK: - 事件
    func refreshDatas(_ data: CutUserModel) {
        if data.usercutstatus == .success {
            bgImgView.isHidden = false
            statusLB.text = "恭喜你，你已砍价至最低价"
        }else if data.usercutstatus == .complete {
            bgImgView.isHidden = false
            statusLB.text = "已成功购买"
        }else if data.usercutstatus == .over {
            bgImgView.isHidden = true
            statusLB.text = "当前砍价已结束"
        }else if data.usercutstatus == .fail {
            bgImgView.isHidden = true
            statusLB.text = "砍价失败"
        }
    }
}

//MARK: - HelpBargainShareBtnView--------------------------
class HelpBargainShareBtnView: UIView {
    //MARK: - 声明属性
    lazy var oneBtn: UIButton = {
        let btn = UIButton.makeButton(font: UIFont.systemFont(ofSize: 18.up), title: "分享到群可多砍一次", titleColor: UIColor.white, image: nil, bgColor: UIColor.white)
        btn.setBackgroundImage(UIImage(named: "helpBargain_btn_share_normal"), for: .normal)
        btn.setBackgroundImage(UIImage(named: "helpBargain_btn_share_normal"), for: .highlighted)
        return btn
    }()
    
    lazy var twoBtn: UIButton = {
        let btn = UIButton.makeButton(font: UIFont.systemFont(ofSize: 18.up), title: "直接购买", titleColor: UIColor.colorWithHexString("707AFF"), image: nil, bgColor: UIColor.white)
        btn.setBackgroundImage(UIImage(named: "helpBargain_btn_share_border"), for: .normal)
        btn.setBackgroundImage(UIImage(named: "helpBargain_btn_share_border"), for: .highlighted)
        return btn
    }()
    
    var space: CGFloat = 12
    
    //MARK: - 初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    //MARK: - 搭建UI
    func setupUI() {
        self.addSubview(oneBtn)
        self.addSubview(twoBtn)
        
        oneBtn.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.width.equalTo(303.up)
            make.height.equalTo(44.up)
            make.top.equalToSuperview().offset(space)
            
        }
        
        twoBtn.snp.makeConstraints { (make) in
            make.left.right.equalTo(oneBtn)
            make.top.equalTo(oneBtn.snp.bottom).offset(20)
            make.height.equalTo(44.up)
            make.bottom.equalToSuperview().offset(-space)
        }
    }
    
    //MARK: - 事件
    func refreshDatas(_ data: CutUserModel) {
        oneBtn.setTitle("分享到群可多砍一次", for: .normal)
        twoBtn.setTitle("直接购买", for: .normal)
        
        let state = 1
        if state == 0 {
            oneBtn.isHidden = false
            twoBtn.isHidden = true
            
            oneBtn.snp.remakeConstraints { (make) in
                make.centerX.equalToSuperview()
                make.width.equalTo(303.up)
                make.height.equalTo(44.up)
                make.top.equalToSuperview().offset(space)
                make.bottom.equalToSuperview().offset(-space)
            }
            
            twoBtn.snp.updateConstraints { (make) in
                make.height.equalTo(0)
            }
        }else {
            oneBtn.isHidden = false
            twoBtn.isHidden = false
            
            oneBtn.snp.remakeConstraints { (make) in
                make.centerX.equalToSuperview()
                make.width.equalTo(303.up)
                make.height.equalTo(44.up)
                make.top.equalToSuperview().offset(space)
            }
            
            twoBtn.snp.updateConstraints { (make) in
                make.height.equalTo(44.up)
            }
        }
        
        oneBtn.zoomAnimation()
    }
}

//MARK: - HelpBargainFriendsView--------------------------
class HelpBargainFriendsView: UIView, UICollectionViewDataSource, UICollectionViewDelegate {
    //MARK: - 声明属性
    lazy var topLeftLineImgView: UIImageView = {
        let imgView = UIImageView(image: UIImage(named: "helpBargain_img_friendsTopLine_left"))
        imgView.contentMode = .scaleAspectFill
        return imgView
    }()
    
    lazy var topTitleLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 14.up), text: "好友助力榜", textColor: UIColor.black, numberLine: 1, alignment: .center)
        return label
    }()
    
    lazy var topRightLineImgView: UIImageView = {
        let imgView = UIImageView(image: UIImage(named: "helpBargain_img_friendsTopLine_right"))
        imgView.contentMode = .scaleAspectFill
        return imgView
    }()
    
    lazy var friendsListCollectionView : UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
        layout.sectionInset = UIEdgeInsets.init(top: 0, left: space, bottom: 0, right: space)
        layout.minimumLineSpacing = space
        layout.itemSize = CGSize(width: itemW, height: itemH)
        let collectionView = UICollectionView(frame: .zero,
                                              collectionViewLayout: layout)
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.backgroundColor = UIColor.white
        collectionView.dataSource = self
        collectionView.delegate   = self
        collectionView.register(HBFriendsCollectionCell.self, forCellWithReuseIdentifier: HBFriendsCollectionCell.reuseId())
        return collectionView
    }()
    
    var space: CGFloat = 16
    let itemW: CGFloat = 44.up
    let itemH: CGFloat = 74.up
    var dataList: [Any] = ["","",""]
 
    //MARK: - 初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    //MARK: - 搭建UI
    func setupUI() {
        self.addSubview(topLeftLineImgView)
        self.addSubview(topTitleLB)
        self.addSubview(topRightLineImgView)
        self.addSubview(friendsListCollectionView)
        
        let topH: CGFloat = 20.up
        topTitleLB.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.centerX.equalToSuperview()
            make.height.equalTo(topH)
        }
        topTitleLB.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 800), for: .horizontal)
        topTitleLB.setContentHuggingPriority(UILayoutPriority(rawValue: 800), for: .horizontal)
        
        topLeftLineImgView.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.right.equalTo(topTitleLB.snp.left).offset(-10)
            make.centerY.equalTo(topTitleLB)
            make.height.equalTo(1)
        }
        
        topRightLineImgView.snp.makeConstraints { (make) in
            make.left.equalTo(topTitleLB.snp.right).offset(10)
            make.right.equalToSuperview()
            make.centerY.equalTo(topTitleLB)
            make.height.equalTo(1)
        }
        
        friendsListCollectionView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(topTitleLB.snp.bottom).offset(24)
            make.height.equalTo(itemH)
            make.bottom.equalToSuperview().offset(-20)
        }
    }
    
    //MARK: - 事件
    func refreshDatas(_ data: CutUserModel) {
        self.friendsListCollectionView.reloadData()
    }
    
    //MARK: - 代理
    //MARK: UICollectionViewDelegate
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.dataList.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HBFriendsCollectionCell.reuseId(), for: indexPath) as! HBFriendsCollectionCell
        if indexPath.row < self.dataList.count {
            let model = self.dataList[indexPath.row]
            cell.cellRefreshDatas(model)
        }
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if indexPath.row < self.dataList.count {
            
        }
    }
}

class HBFriendsCollectionCell: UICollectionViewCell {
    //MARK: - 声明属性
    lazy var photoImgView: UIImageView = {
        let imgView = UIImageView()
        return imgView
    }()
    
    lazy var priceLB: UILabel = {
        let label = UILabel.makeLabel(font: UIFont.systemFont(ofSize: 12.up), text: "0.00元", textColor: UIColor.colorWithHexString("FF6828"), numberLine: 1, alignment: .center)
        return label
    }()

    let photoWH: CGFloat = 44.up
    
    //MARK: - 初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    static func reuseId() -> String {
        return NSStringFromClass(HBFriendsCollectionCell.self)
    }
    
    //MARK: - 搭建UI
    func setupUI() {
        contentView.addSubview(photoImgView)
        contentView.addSubview(priceLB)
        
        photoImgView.snp.makeConstraints { (make) in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(photoWH)
        }
        photoImgView.cornerRadius(photoWH/2.0)
        
        priceLB.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(photoImgView.snp.bottom)
        }
    }
    
    //MARK: - 刷新数据
    func cellRefreshDatas(_ data:Any) {
        photoImgView.image = UIImage(named: "helpBargain_img_douNiu_logo")
        priceLB.text = "12.98元"
    }
}

//MARK: - HelpBargainPeoplePlayView--------------------------
class HelpBargainPeoplePlayView: UIView {
    //MARK: - 声明属性
    var space: CGFloat = 12
    
    //MARK: - 初始化
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    //MARK: - 搭建UI
    func setupUI() {
        
    }
    
    //MARK: - 事件
    func refreshDatas(_ data: CutUserModel) {
        
    }
}
